'''
Created on 23/03/2009

@author: eh01
'''
from im.ds.dst import DST
from im.ds.dso import DSO
import unittest


class Test(unittest.TestCase):


    def setUp(self):
        pass


    def tearDown(self):
        pass


    def test_to_xml(self):
        dst1 = DST("testSubject1", "testPredicate1", "testObject1", None, None)
        dst2 = DST("testSubject2", "testPredicate2", None, "testLiteral2", "String")
        dst_list = [dst1, dst2]
        dso = DSO(dsts = dst_list)
        print dso.to_xml()
    
    def test_unmarshal(self):
        subject1 = "testSubject1"
        predicate1 = "testPredicate1"
        object1 = "testObject1"
        subject2 = "testSubject2"
        predicate2 = "testPredicate2"
        literal2 = "testLiteral2"
        literal_type2 = "testLiteralType2"
        xml = "<dso>"
        xml += "<dst>"
        xml += "<subject>" + subject1 + "</subject>"
        xml += "<predicate>" + predicate1 + "</predicate>"
        xml += "<object>" + object1 + "</object>"
        xml += "</dst>"
        xml += "<dst>"
        xml += "<subject>" + subject2 + "</subject>"
        xml += "<predicate>" + predicate2 + "</predicate>"
        xml += "<literal>" + literal2 + "</literal>"
        xml += "<literalType>" + literal_type2 + "</literalType>"
        xml += "</dst>"
        xml += "</dso>"
        
        dso = DSO(xml_string = xml)
        assert len(dso.get_dsts()) == 2
        dsts = dso.get_dsts()
        dst1 = dsts[0]
        dst2 = dsts[1]
        assert dst1.get_subject() == subject1
        assert dst1.get_predicate() == predicate1
        assert dst1.get_object() == object1
        assert dst1.get_literal() == None
        assert dst1.get_literal_type() == None
        assert dst2.get_subject() == subject2
        assert dst2.get_predicate() == predicate2
        assert dst2.get_object() == None
        assert dst2.get_literal() == literal2
        assert dst2.get_literal_type() == literal_type2        
        
if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.test_to_xml']
    unittest.main()